<template>
	<view>
		<u-upload :action="action" :file-list="fileList" @on-remove="delLifePhotos" upload-text="拍照" 
		:source-type="['camera']" @on-success="success"></u-upload>
		<view @click="sumit()" class="butt">
			提交确认到达
		</view>
	</view>
</template>

<script>
	import {
		API_URL
	} from '@/env'
	export default {
		data() {
			return {
				// 演示地址，请勿直接使用
				action: API_URL + '/api/common/upload?token=' + uni.getStorageSync('token') + '&type=0',
				fileList: [
					
				],
				file:[]
			
			}
		},
		onLoad(option) {
			this.id = option.id
			this.item_id = option.item_id
			this.status = option.status
		},
		methods: {
			success(e){
				this.file.push(e.data.fullurl)
			},
			sumit(){
				let that = this;
				if(this.file.length <= 0){
					that.$u.toast('请上传后在提交');
					return false
				}
				
				that.$http('order.operationTechnicianOrderStatus', {
					id: that.id,
					order_item_id: that.item_id,
					status:that.status,
					images:that.file.join(',')
				}, '加载中...').then(res => {
					that.$u.toast(res.msg);
					if(res.code == 1){
						setTimeout(function(){
							uni.navigateBack({
								data: 1
							})
						},1500)
					}
				})
			},
			getLifePhotos(){
				this.$http('user.getLifePhotos', {
					
				}).then(res => {
					this.fileList = res.data
				})
			},
			delLifePhotos(e){
				let index = e>=0?e:0
				let id = this.fileList[index].id
				this.file.splice(index,1)
				this.del(id);
				
			},
			del(id){
				this.$http('user.delLifePhotos', {
					id:id
				}).then(res => {
					this.$u.toast(res.msg);
					this.getLifePhotos()
				})
			}
		}
	}
</script>
<style>
	.u-list-item {
		width: 750px;
		height: 550px;
	}
	.butt {
		background: #39b54a;
		    color: white;
		    width: 60%;
		    margin: auto;
		    text-align: center;
		    padding: 10px;
		    border-radius: 5px;
	}
</style>